package com.tedu.openmedical.medicalsystem.base.utils;

import com.tedu.openmedical.medicalsystem.base.domain.SimpleUser;
import com.tedu.openmedical.medicalsystem.user.pojo.entity.User;
import com.tedu.openmedical.medicalsystem.user.pojo.vo.ActiveUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.BeanUtils;

public class ShiroSecurityUtils {

    /**
     * 获取当前登录用户 返回ActiverUser
     * @return return
     */
    public static ActiveUser getCurrentActiveUser(){
        Subject subject = SecurityUtils.getSubject();
        User user = (User)subject.getPrincipal();
        ActiveUser activeUser = new ActiveUser();
        BeanUtils.copyProperties(user,activeUser);
        return activeUser;
    }

    /**
     * 获取当前登录用户 返回SimpleUser
     * @return return
     */
    public static SimpleUser getCurrentSimpleUser(){
        Subject subject = SecurityUtils.getSubject();
        User user = (User)subject.getPrincipal();
        //ActiveUser principal = (ActiveUser)subject.getPrincipal();
        return new SimpleUser(Long.toString(user.getUserId()),user.getUserName());
    }
}
